package test.medallia;

public class Lists {

	public static void main(String[] args) {

		Node nodeE = new Node("e", null);
		Node nodeD = new Node("d", nodeE);
		Node nodeC = new Node("c", nodeD);
		Node nodeB = new Node("b", nodeC);
		Node nodeA = new Node("a", nodeB);

		Node node = reverse(nodeA);

		while (node != null) {
			System.out.println(node.getValue());
			node = node.getNext();
		}
	}

	public static Node reverse(Node head) {

		return recursiveHelper(null, head);
	}

	private static Node recursiveHelper(Node prev, Node curr) {

		if (curr == null) {

			return prev;

		} else {

			Node next = curr.getNext();
			curr.setNext(prev);

			return recursiveHelper(curr, next);
		}
	}
}
